package cn.tedu;

import com.alibaba.druid.pool.DruidDataSource;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtils {
    private  static DruidDataSource ds;
    static {
        ds = new DruidDataSource();
        ds.setUrl("jdbc:mysql://localhost:3307/empdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai");
        ds.setUsername("root");
        ds.setPassword("147258bb");
        //设置初始连接数量
        ds.setInitialSize(3);
        //设置最大连接数量
        ds.setMaxActive(5);

    }
    public static Connection getConn() throws SQLException {
        //从连接池中获取连接  异常抛出
        Connection conn = ds.getConnection();
        System.out.println("连接对象："+conn);
        return conn;
    }
}

